home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / smoothTangent.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.7 KB  |  318 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Nov. 14, 1999
  22. //  Author:         ms
  23. //
  24. //  Description:
  25. //      The smoothTangent() procedure smooths the tangent :-)
  26. //
  27. //  Input Arguments:
  28. //      None.
  29. //
  30. //  Return Value:
  31. //      None.
  32. //
  33.  
  34. proc performSmoothTangentPreset( int $history,
  35.                                   int $whichDirection,
  36.                                   string $surfaces[],
  37.                                   string $results[] )
  38. //
  39. //    Description:
  40. //        This proc takes the given surface isoparms and groups
  41. //        them according to the surface, then executes an "smoothTangentSrf"
  42. //        command on each surface.  eg. if the isoparms coming in are:
  43. //            surface1.u[0.33] surface1.v[0.66] surface2.v[0.55]
  44. //        this proc will execute these three commands:
  45. //            smoothTangentSrf ... -d 1 -p 0.33 surface1;    // U direction
  46. //            smoothTangentSrf ... -d 0 -p 0.33 -rpo 1 surface1;    // V direction
  47. //            smoothTangentSrf ... -d 0 -p 0.55 surface2;    // V direction
  48. //
  49. //         WARNING - assumes that the surfaces coming into this proc
  50. //         are isoparms, ie. they have the format:
  51. //        <surfaceName>.u[<parameterValue>]
  52. //         or <surfaceName>.v[<parameterValue>]
  53. //
  54. //
  55. //      whichDirection = 0 - whatever the selection is
  56. //      whichDirection = 1 - if points selected, only smooth in U
  57. //      whichDirection = 2 - if points selected, only smooth in V
  58. {
  59.     int $addOrComplement = true;
  60.     int $multi = false;
  61.     int $numKnots = 7;
  62.     int $rpo = true;
  63.  
  64.     string $cmd = "smoothTangentSurface" + " -ch " + $history + 
  65.         " -rpo " + $rpo + " ";
  66.  
  67.     string $smoothResults[];
  68.     string $results[];
  69.  
  70.     // for each string returned from groupObjectsByName, put together
  71.     // an insertKnotSurface cmd and execute it.
  72.     //
  73.     string $groupStrings[];
  74.     $groupStrings = groupObjectsByName( $surfaces, "\\." );
  75.     int $numStrings = size( $groupStrings );
  76.     string $execCmd;
  77.  
  78.     for( $i = 0; $i < $numStrings; $i ++ ) {
  79.  
  80.         $execCmd = $cmd + " ";
  81.  
  82.         string $parms[];
  83.         $numParms = `tokenize $groupStrings[$i] $parms`;
  84.         string $foundUStr = `match "\\.u\\[" $groupStrings[$i]`;
  85.         string $foundVStr = `match "\\.v\\[" $groupStrings[$i]`;
  86.         string $foundUVStr = `match "\\.uv\\[" $groupStrings[$i]`;
  87.         int $foundU = (size($foundUStr) > 0);
  88.         int $foundV = (size($foundVStr) > 0);
  89.         int $foundUV = (size($foundUVStr) > 0);
  90.  
  91.         if( $numParms > 1 || $foundUV ) {
  92.  
  93.             // Get the surface name
  94.             //
  95.             string $surfaceName[];
  96.             tokenize $groupStrings[$i] "\\." $surfaceName;
  97.  
  98.             int $doneSome = false;
  99.  
  100.             // Format the parameter values with "-p" flag
  101.             // Direction is set with "-d 1" flag
  102.             //
  103.             if( $foundU > 0 ||
  104.                 ($foundUV > 0 && ((0 == $whichDirection) ||
  105.                                   (1 == $whichDirection)))) {
  106.                 $execCmd += " -d 1 ";
  107.  
  108.                 $doneSome = true;
  109.  
  110.                 int $p;
  111.                 for( $p = 0; $p < $numParms; $p ++ ) {
  112.                     string $regularExpr = "\\.u\\[.*\\]";
  113.                     string $parm = match($regularExpr, $parms[$p]);
  114.                     $strLen = size($parm);
  115.                     if( $strLen > 0 ) {
  116.  
  117.                         // we could have an isoparam like .u[][a:b]
  118.                         // so, we also do a tokenize filtering only the .u[]
  119.                         // portion out.
  120.                         //
  121.                         string $ucomp[] ;
  122.                         int $nc ;
  123.                         $nc = `tokenize $parm "]" $ucomp` ;
  124.                         if( size($ucomp) > 0 )  {
  125.                             $parm = substring( $ucomp[0], 4, $strLen-1 );
  126.                                // append to $execCmd as a -p flag
  127.                             //
  128.                             $execCmd += " -p ";
  129.                             $execCmd += $parm;
  130.                         }
  131.  
  132.                     } else {
  133.                         string $regularExpr = "\\.uv\\[.*\\]\\[.*\\]";
  134.                         string $parm = match($regularExpr, $parms[$p]);
  135.                         $strLen = size($parm);
  136.                         if( $strLen > 0 ) {
  137.  
  138.                             // change ".uv[0.444][0.66]" to ".uv[0.44"
  139.                             $parm = substitute( "\\]\\[.*\\]", $parm, "" );
  140.  
  141.                             $strLen = size($parm);
  142.                             $parm = substring( $parm, 5, $strLen );
  143.                             $execCmd += " -p ";
  144.                             $execCmd += $parm;
  145.                         }
  146.                     }
  147.                 }
  148.  
  149.                 // Add the surface name
  150.                 //
  151.                 $execCmd += " ";
  152.                 $execCmd += $surfaceName[0];
  153.  
  154.                 // If V direction is also specified, then execute 
  155.                 // the U direction insert cmd right here
  156.                 //
  157.                 if( ($foundV > 0 || $foundUV > 0) ) {
  158.  
  159.                     // Insert command returns the new surface and surface node.
  160.                     // Substitute the new surface as the surface name so if
  161.                     // inserting in the V direction too, it will be 
  162.                     // chained in sequence.
  163.                     // Also, copy the results for this insert commadn to
  164.                     // the results array.
  165.                     //
  166.                     string $tempResults[];
  167.                     $tempResults = evalEcho( $execCmd );
  168.                     int $numTempResults = size( $tempResults );
  169.                     if( $numTempResults == 2) {
  170.                         $surfaceName[0] = $tempResults[0];
  171.                         int $numResults = size( $results );
  172.                         for( $j = 0; $j < $numTempResults; $j ++, 
  173.                             $numResults ++ ) {
  174.                             $results[$numResults] = $tempResults[$j];
  175.                         }
  176.                     }
  177.                 }
  178.             }
  179.  
  180.             if( $foundV > 0 ||
  181.                 ($foundUV > 0 && ((0 == $whichDirection) ||
  182.                                   (2 == $whichDirection)))) {
  183.  
  184.                 // If U direction was already executed, then make sure
  185.                 // we do "-rpo 1".  Otherwise, just set the direction.
  186.                 //
  187.                 if( ($history > 0) && $doneSome ) {
  188.                     $execCmd = "insertKnotSurface" + " -ch " + $history +
  189.                             " -rpo 1 -d 0 ";
  190.                 } else {
  191.                     $execCmd = $cmd + " -d 0 ";
  192.                 }
  193.  
  194.                 int $p;
  195.                 for( $p = 0; $p < $numParms; $p ++ ) {
  196.                     string $regularExpr = "\\.v\\[.*\\]";
  197.                     string $parm = match($regularExpr, $parms[$p]);
  198.                     $strLen = size($parm);
  199.                     if( $strLen > 0 ) {
  200.  
  201.                         // we could have an isoparam like .v[][a:b]
  202.                         // so, we also do a tokenize filtering only the .v[]
  203.                         // portion out. 
  204.                         //
  205.                         string $vcomp[] ;
  206.                         int $nc ;
  207.                         $nc = `tokenize $parm "]" $vcomp` ;
  208.                         if( size($vcomp) > 0 ) {
  209.                             $parm = substring( $vcomp[0], 4, $strLen-1 );
  210.                             // append to $execCmd as a -p flag
  211.                             $execCmd += " -p ";
  212.                             $execCmd += $parm;
  213.                         }
  214.  
  215.                     } else {
  216.                         string $regularExpr = "\\.uv\\[.*\\]\\[.*\\]";
  217.                         string $parm = match($regularExpr, $parms[$p]);
  218.                         $strLen = size($parm);
  219.                         if( $strLen > 0 ) {
  220.  
  221.                             // change ".uv[0.444][0.66]" to "0.66]"
  222.                             $parm = substitute( "\\.uv\\[.*\\]\\[",$parm,"");
  223.  
  224.                             $strLen = size($parm);
  225.                             $parm = substring( $parm, 1, $strLen-1 );
  226.                             $execCmd += " -p ";
  227.                             $execCmd += $parm;
  228.                         }
  229.                     }
  230.                 }
  231.                 // Add the surface name
  232.                 //
  233.                 $execCmd += " ";
  234.                 $execCmd += $surfaceName[0];
  235.             }
  236.  
  237.         }
  238.         else {
  239.             $execCmd += $groupStrings[$i];
  240.         }
  241.  
  242.         // execute $cmd + $groupStrings[$i]    
  243.         if( catch( $smoothResults = evalEcho( $execCmd))) {
  244.             warning(" Problem evaluating smooth tangent command: " + $cmd +
  245.             $groupStrings[$i] + "\n");
  246.         }
  247.         else {
  248.             int $j;
  249.             int $numResults = size( $results );
  250.             int $numsmoothResults = size( $smoothResults );
  251.             for( $j = 0; $j < $numsmoothResults; $j ++, $numResults ++ ) {
  252.                 $results[$numResults] = $smoothResults[$j];
  253.             }
  254.         }
  255.     }
  256.  
  257.     if( 0 == size($results) ) {
  258.         error ("Smooth Tangent: failed on the input surfaces.");
  259.     }
  260. }
  261.  
  262. global proc smoothTangent()
  263. {
  264.     int $doHistory = `constructionHistory -q -tgl`;
  265.     int $doHilite = false;
  266.  
  267.     // Get a list of each type of acceptable object type - surfaces and curves.
  268.     //
  269.     global int $gSelectSurfaceParmPointsBit;
  270.     global int $gSelectEditPointsBit;
  271.     global int $gSelectIsoparmsBit;
  272.  
  273.     string $surfaceIsoparmList[] = `filterExpand -ex true -sm $gSelectIsoparmsBit -sm $gSelectSurfaceParmPointsBit`;
  274.  
  275.     if( 0 == size($surfaceIsoparmList) ) {
  276.         error( "Smooth Tangent: No valid selection.  Select NURBS " +
  277.                "surface point(s) or isoparm(s)." );
  278.         return;
  279.     }
  280.  
  281.     string $curr = `currentCtx`;
  282.     int $whichDirection = 0;
  283.     if( `curveEditorCtx -exists $curr` ) {
  284.         $whichDirection = `curveEditorCtx -q -dir $curr`;
  285.     }
  286.  
  287.  
  288.     string $surfaceResults[]; // 
  289.     if( size($surfaceIsoparmList) > 0 ) {
  290.         if( !$doHilite ) $doHilite = `shouldHiliteAfterCompute`;
  291.         performSmoothTangentPreset( $doHistory, $whichDirection,
  292.                                     $surfaceIsoparmList, $surfaceResults );
  293.     }
  294.  
  295.     if( size($surfaceResults) == 0 ) {
  296.         error( "Smooth Tangent failed on the selected items. You must " +
  297.                "select NURBS surface points or isoparms." );
  298.     }
  299.     else {
  300.         // Select all the results with one select command.  
  301.         //
  302.         string $selectString;
  303.         $selectString = "select -r ";
  304.         int $i;
  305.  
  306.         int $numSurfaces = size($surfaceIsoparmList);
  307.         for( $i = 0; $i < $numSurfaces; $i ++ ) {
  308.             $selectString += $surfaceIsoparmList[$i];
  309.             $selectString += " ";
  310.         }
  311.         $selectString += ";";
  312.         if( $doHilite ) $selectString += "hilite;";
  313.  
  314.         eval($selectString);
  315.     }
  316. }
  317.  
  318.